class TrackingResponse {
  final String requestId;
  final bool success;
  final String message;
  final int code;
  final TrackingData data;
  final int time;
  final int usage;

  TrackingResponse({
    required this.requestId,
    required this.success,
    required this.message,
    required this.code,
    required this.data,
    required this.time,
    required this.usage,
  });

  factory TrackingResponse.fromJson(Map<String, dynamic> json) {
    return TrackingResponse(
      requestId: json['request_id'],
      success: json['success'],
      message: json['message'],
      code: json['code'],
      data: TrackingData.fromJson(json['data']),
      time: json['time'],
      usage: json['usage'],
    );
  }
}

class TrackingData {
  final int status;
  final String statusText;
  final String number;
  final String msg;
  final String expName;
  final List<TrackingInfo> info;

  TrackingData({
    required this.status,
    required this.statusText,
    required this.number,
    required this.msg,
    required this.expName,
    required this.info,
  });

  factory TrackingData.fromJson(Map<String, dynamic> json) {
    return TrackingData(
      status: json['status'],
      statusText: json['status_text'],
      number: json['number'],
      msg: json['msg'],
      expName: json['exp_name'],
      info: (json['info'] as List)
          .map((item) => TrackingInfo.fromJson(item))
          .toList(),
    );
  }

  String getStatusDescription() {
    switch (status) {
      case 0:
        return '在途';
      case 1:
        return '揽件';
      case 2:
        return '问题件';
      case 3:
        return '已签收';
      case 4:
        return '退签';
      case 5:
        return '派件';
      case 6:
        return '退回';
      default:
        return '未知状态';
    }
  }
}

class TrackingInfo {
  final String time;
  final String content;

  TrackingInfo({
    required this.time,
    required this.content,
  });

  factory TrackingInfo.fromJson(Map<String, dynamic> json) {
    return TrackingInfo(
      time: json['time'],
      content: json['content'],
    );
  }
}